package com.example.wananrdroid.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.wananrdroid.R;
import com.example.wananrdroid.bean.GuangBean;

import java.util.List;

public class GuangAdapter extends RecyclerView.Adapter<GuangAdapter.ViewHolder> {
    private Context context;
    private List<GuangBean.DataBean.DatasBean> datas;
    private OnContextClickListener onContextClickListener;
    public interface OnContextClickListener{
        void oncontextclicklistener(View v,int position);
    }

    public void setOnContextClickListener(OnContextClickListener onContextClickListener) {
        this.onContextClickListener = onContextClickListener;
    }

    public GuangAdapter(Context context, List<GuangBean.DataBean.DatasBean> datas) {
        this.context = context;
        this.datas = datas;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.guang_item, parent, false);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        GuangBean.DataBean.DatasBean datasBean = datas.get(position);
        holder.data.setText(datasBean.getNiceDate());
        holder.user.setText(datasBean.getShareUser());
        holder.title.setText(datasBean.getTitle());
        holder.name.setText(datasBean.getChapterName()+datasBean.getSuperChapterName());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onContextClickListener.oncontextclicklistener(view,position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView user;
        TextView title;
        TextView data;
        TextView name;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            data=itemView.findViewById(R.id.niceShareDate);
            user=itemView.findViewById(R.id.user);
            title=itemView.findViewById(R.id.tilte);
            name=itemView.findViewById(R.id.name);
        }
    }
}
